/**
 * Copyright (C) 2008 ChangSha WangWin Science & Technology CO,.LTD. All rights reserved.
 * WangWin PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

/**
 * Copyright (C) 2002-2008 WUZEWEN. All rights reserved.
 * WUZEWEN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 * This software is the confidential and proprietary information of
 * WuZeven, Personal. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with WuZeven.
 */

package com.kingcore.pda.admin.controller;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import wzw.util.DebugUtils;

import com.kingcore.pda.base.controller.PdaAction;
import com.kingcore.pda.core.util.DbUtils;

/**
 * <p>系统管理员事件处理控制器。</p>
 * @author Zeven on 2008-1-25
 * @version	1.0
 * @see		Object#equals(java.lang.Object)
 * @see		Object#hashCode()
 * @see		HashMap
 * @since	JDK5
 */

public class AdminAction extends PdaAction {

	protected Logger log = Logger.getLogger( this.getClass() );

	/* (non-Javadoc)
	 * @see com.kingcore.pda.base.controller.AbstractPdaAction#executeAction(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward executeAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		String method = request.getParameter("method");
		
		log.debug("action is "+method);
		if("getProjectList".equals( method )){
			return getProjectList(mapping, form, request, response);
		}else if("getProjectList".equals( method )){
			
		}

		return null;
	}

	private ActionForward getProjectList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {


		// 执行数据库操作
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		String sql="";

		try {
			conn = DbUtils.getConnection();
			stmt = conn.createStatement();
			sql = "select * from pda_project";
			rs = stmt.executeQuery( sql );
			
			//outPutResultSet( rs );
			
			//ResultSetWrapper rsw = new ResultSetWrapper(rs);
			List rsw = DbUtils.resultSet2List(rs);
			
			//outPutResultSet( rsw );
			DebugUtils.consolePrint( rsw );
				
			request.setAttribute("projects", rsw );
			
			log.debug("----------------------- go to getProjectList-success");
			return mapping.findForward("getProjectList-success");
			
		}catch(Exception e){
			e.printStackTrace();

		} finally {
			try{
				if(rs!=null)
					rs.close() ;
				if(stmt!=null)
					stmt.close() ;
				if( conn!=null )
					conn.close() ;

			} catch(SQLException e){
				e.printStackTrace();
			}
		}
		return null;
	}


	/**
	 * <p>java类文件的说明...</p>
	 * @author Zeven on 2008-1-25
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

}
